package com.atguigu.common.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

public class MyConstraintValidator implements ConstraintValidator<MyValidate, Integer> {
    Set<Integer> set = new HashSet<>();

    @Override
    public void initialize(MyValidate constraintAnnotation) {
        int a[] = constraintAnnotation.vals();
        for (int i : a) {
            set.add(a[i]);
        }
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        return set.contains(value);
    }
}
